/****************************************************
	文件：GameRoot.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2020/9/25 21:22:19
	功能：Game 根节点
*****************************************************/

using System;
using HTUtility;
using UnityEngine;

namespace RedSpotSystem
{
    public class GameRoot : MonoBehaviour
    {
        private RedSpotSys mRedSpotSys;
        private SchemesMgr mSchemesMgr;

        private void Start()
        {
            Init();
        }
        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.Q)) //打印所有红点个数
            {
                LogAllRedNum();
            }

            if (Input.GetKeyDown(KeyCode.A)) //增加红点
            {
                SetRedNum(GEnum.E_UIComp.UIHorseNormal, 1);
            }
            if (Input.GetKeyDown(KeyCode.S))
            {
                SetRedNum(GEnum.E_UIComp.UIHorseSpecial, 2);
            }
            if (Input.GetKeyDown(KeyCode.D))
            {
                SetRedNum(GEnum.E_UIComp.UIWingNormal, 3);
            }
            if (Input.GetKeyDown(KeyCode.F))
            {
                SetRedNum(GEnum.E_UIComp.UIWingSpecial, 4);
            }

            if (Input.GetKeyDown(KeyCode.Z)) //减少红点
            {
                SetRedNum(GEnum.E_UIComp.UIHorseNormal, 0);
            }
            if (Input.GetKeyDown(KeyCode.X))
            {
                SetRedNum(GEnum.E_UIComp.UIHorseSpecial, 1);
            }
            if (Input.GetKeyDown(KeyCode.C))
            {
                SetRedNum(GEnum.E_UIComp.UIWingNormal, 2);
            }
            if (Input.GetKeyDown(KeyCode.V))
            {
                SetRedNum(GEnum.E_UIComp.UIWingSpecial, 3);
            }

            if (Input.GetKeyDown(KeyCode.O)) //非叶子节点不可设置红点
            {
                SetRedNum(GEnum.E_UIComp.UIHorse, 1);
            }
            if (Input.GetKeyDown(KeyCode.P))
            {
                SetRedNum(GEnum.E_UIComp.UICuriosity, 1);
            }
        }

        private void Init()
        {
            HTLoggerInstaller.Instance.Install();
            mSchemesMgr = SchemesMgr.Instance;
            mSchemesMgr.Init();
            mRedSpotSys = RedSpotSys.Instance;
            mRedSpotSys.Init();

            InitAllRedData();
        }


        #region For Test
        private RedSpotData mUICuriosityRedData;
        private RedSpotData mUIHorseRedData;
        private RedSpotData mUIHorseNormalRedData;
        private RedSpotData mUIHorseSpecialRedData;
        private RedSpotData mUIWingRedData;
        private RedSpotData mUIWingNormalRedData;
        private RedSpotData mUIWingSpecialRedData;
        /// <summary>
        /// 初始化所有红点数据
        /// </summary>
        private void InitAllRedData()
        {
            mUICuriosityRedData = mRedSpotSys[GEnum.E_UIComp.UICuriosity];
            mUIHorseRedData = mRedSpotSys[GEnum.E_UIComp.UIHorse];
            mUIHorseNormalRedData = mRedSpotSys[GEnum.E_UIComp.UIHorseNormal];
            mUIHorseSpecialRedData = mRedSpotSys[GEnum.E_UIComp.UIHorseSpecial];
            mUIWingRedData = mRedSpotSys[GEnum.E_UIComp.UIWing];
            mUIWingNormalRedData = mRedSpotSys[GEnum.E_UIComp.UIWingNormal];
            mUIWingSpecialRedData = mRedSpotSys[GEnum.E_UIComp.UIWingSpecial];

            mUICuriosityRedData.Bind(new UIComps(gameObject))
                .Subscribe((self) => { HTLogger.Debug("Update RedSpot , {0} RedSpot Num is : {1}", (self.Self).ToString(), self.Count.Value); });
            mUIHorseRedData.Bind(new UIComps(gameObject))
                .Subscribe((self) => { HTLogger.Debug("Update RedSpot , {0} RedSpot Num is : {1}", (self.Self).ToString(), self.Count.Value); });
            mUIHorseNormalRedData.Bind(new UIComps(gameObject))
                .Subscribe((self) => { HTLogger.Debug("Update RedSpot , {0} RedSpot Num is : {1}", (self.Self).ToString(), self.Count.Value); });
            mUIHorseSpecialRedData.Bind(new UIComps(gameObject))
                .Subscribe((self) => { HTLogger.Debug("Update RedSpot , {0} RedSpot Num is : {1}", (self.Self).ToString(), self.Count.Value); });
            mUIWingRedData.Bind(new UIComps(gameObject))
                .Subscribe((self) => { HTLogger.Debug("Update RedSpot , {0} RedSpot Num is : {1}", (self.Self).ToString(), self.Count.Value); });
            mUIWingNormalRedData.Bind(new UIComps(gameObject))
                .Subscribe((self) => { HTLogger.Debug("Update RedSpot , {0} RedSpot Num is : {1}", (self.Self).ToString(), self.Count.Value); });
            mUIWingSpecialRedData.Bind(new UIComps(gameObject))
                .Subscribe((self) => { HTLogger.Debug("Update RedSpot , {0} RedSpot Num is : {1}", (self.Self).ToString(), self.Count.Value); });
        }
        /// <summary>
        /// 打印所有红点个数
        /// </summary>
        private void LogAllRedNum()
        {
            for (int i = 2; i < (int)GEnum.E_UIComp.MAX; i++)
            {
                GEnum.E_UIComp eComp = (GEnum.E_UIComp)i;
                string name = eComp.ToString();
                int num = mRedSpotSys[eComp].Count.Value;
                HTLogger.Debug("{0} RedSpot Num is : {1}", name, num);
            }
        }
        /// <summary>
        /// 设置指定红点的红点个数
        /// </summary>
        /// <param name="eComp">UIComp枚举</param>
        /// <param name="curNum">当前红点个数</param>
        private void SetRedNum(GEnum.E_UIComp eComp, int curNum)
        {
            RedSpotData data = mRedSpotSys[eComp];
            data.SetRedNum(curNum);
        }
        #endregion
    }
}
